package cn.liufuwen.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import cn.liufuwen.entity.OrdersDTO;
import cn.liufuwen.entity.OrdersDetailDTO;
import cn.liufuwen.entity.UserDTO;
import cn.liufuwen.service.OrdersDetailService;
import cn.liufuwen.service.OrdersService;
import lombok.extern.java.Log;
@Log
@RestController
@RequestMapping("/ordersDetail")
public class OrdersDetailController {
	@Reference(version = "${demo.service.version}")
	OrdersService ordersService;
	@Reference(version = "${demo.service.version}")
	OrdersDetailService ordersDetailService;
	@RequestMapping("/ordersInfoList")
	public List<OrdersDetailDTO> ordersInfoList(HttpSession session) {
		UserDTO userDTO = (UserDTO)session.getAttribute("USER_SESSION_KEY");
		int userID= userDTO.getId();
		if(ordersDetailService.listOrdersDetail(userID).isEmpty()){
			return null;
		}else{
			List<OrdersDetailDTO> listOrdersDetailDTO = ordersDetailService.listOrdersDetail(userID);
			return listOrdersDetailDTO;
		}
	}
	@RequestMapping("/delGoods")
	public int delGoods(OrdersDetailDTO ordersDetailDTO) {
		int i = 0;
		
		i = ordersDetailService.delGoods(ordersDetailDTO);
		return i;
	}
	@RequestMapping("/subOrders")
	public int subOrders(OrdersDTO ordersDTO) {
		int i = 0;
		i = ordersService.confirmOrders(ordersDTO);
		return i;
	}
	@RequestMapping("/delOrders")
	public int delOrders(OrdersDTO ordersDTO) {
		int i = 0;
		i = ordersService.invalidOrders(ordersDTO);
		return i;
	}
	@RequestMapping("/ordersList")
	public List<OrdersDTO> ordersList(HttpSession session) {
		UserDTO userDTO = (UserDTO)session.getAttribute("USER_SESSION_KEY");
		int userID= userDTO.getId();
		List<OrdersDTO> listOrdersDTO = ordersService.listOrders(userID);
		return listOrdersDTO;
	}
	@RequestMapping("/orderInfo")
	public List<OrdersDetailDTO> orderInfo(HttpSession session,int orderID) {
		UserDTO userDTO = (UserDTO)session.getAttribute("USER_SESSION_KEY");
		int userID= userDTO.getId();
		if(userID>0){
			List<OrdersDetailDTO> listOrdersDTO = ordersDetailService.ordersDetailByID(orderID);
			return listOrdersDTO;
		}else{
			return null;
		}
			
	}
	
}
